using System;
using UnityEngine;
namespace DefaultNamespace.Skill
{
    public class ProjectileController : MonoBehaviour
    {
        public float speed = 10f;
        public float lifetime = 5f;
        public int damage = 10;
        public Action<GameObject> onHit;
        private void Start()
        {
            // Destroy the projectile after its lifetime expires
            Destroy(gameObject, lifetime);
        }
        public void Initialize(GameObject caster,float speed, float lifetime)
        {
            
        }
        private void Update()
        {
            // Move the projectile forward
            transform.Translate(Vector3.forward * speed * Time.deltaTime);
        }
        private void OnTriggerEnter(Collider other)
        {
            // Check if the projectile hits something with a Health component
            HealthSystem targetHealth = other.GetComponent<HealthSystem>();
            if (targetHealth != null)
            {
                targetHealth.TakeDamage(damage);
                onHit?.Invoke(other.gameObject);
            }
            
            // Destroy the projectile on impact
            Destroy(gameObject);
        }
    }
}